import 'package:common_utils/common_utils.dart';
import 'package:study_demo/base/BaseController.dart';
import 'package:get/get.dart';

class CountDownController extends BaseController {
  final String DATE_FORMAT = "%02d:%02d"; // 时间显示格式

  var _num = 0.obs;

  int get num => _num.value;

  set num(int num) {
    _num.value = num;
  }

  var _timeInfo = "".obs;

  String get timeInfo => _timeInfo.value;

  set timeInfo(String timeInfo) {
    _timeInfo.value = timeInfo;
  }

  TimerUtil? _timerUtil;

  @override
  onInit() {
    super.onInit();
    countDown();
  }

  countDown() {
    //计时4秒
    int totalTime = 600 * 1000;
    // 初始化设置
    _timerUtil = new TimerUtil(mTotalTime: totalTime);
    _timerUtil?.setOnTimerTickCallback((int tick) {
      // double _tick = tick / 1000;
      // num = _tick.toInt();
      timeInfo =
          DateUtil.formatDateMs(tick.toInt(), format: "mm:ss").toString();
    });
    _timerUtil?.startCountDown();
  }

  @override
  void dispose() {
    super.dispose();
    _timerUtil?.cancel();
  }
}
